<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">新增用户</h4>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="/project/accountManage/account_save">
    <div class="modal-body">

            <div class="form-group">
                <label class="col-lg-1 control-label">姓名</label>
                <div class="col-lg-6">
                    <input type="text" class="form-control" name="nickName" />
                </div>
            </div>

        <div class="form-group">
            <label class="col-lg-1 control-label">账号</label>
            <div class="col-lg-11">
                <input type="text" class="form-control" name="account"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-1 control-label">密码</label>
            <div class="col-lg-11">
                <input type="text" class="form-control" name="pass"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-1 control-label">微信号</label>
            <div class="col-lg-11">
                <input type="text" class="form-control" name="openId"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-1 control-label">权限</label>
            <div class="col-lg-11">
                <input type="checkbox" name="menu"   value="客户需求"> 客户需求
                <input type="checkbox"  name="menu"  value="需求审核"> 需求审核
                <input type="checkbox"  name="menu" value="需求汇总"> 需求汇总
                <input type="checkbox"  name="menu" value="后台管理"> 后台管理
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-1 control-label">角色</label>
            <div class="col-lg-11">
                <select name="type">
                    <option value="销售">销售</option>
                    <option value="经理">经理</option>
                </select>
            </div>
        </div>

    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<script>

    initCheck();
    //初始化表单验证
    function initCheck() {
        $('#defaultForm')
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    customerName: {
                        message: '不是有效的姓名',
                        validators: {
                            notEmpty: {message: '姓名不能为空'},
                            stringLength: {min: 1,max: 30,message: '名称不能超过30个字符'}
                        }
                    },
                    account: {
                        message: '不是有效的账号',
                        validators: {
                            notEmpty: {message: '账号不能为空'},
                            stringLength: {min: 1,max: 30,message: '账号不能超过30个字符'}
                        }
                    },
                    account: {
                        message: '密码不能为空',
                        validators: {
                            notEmpty: {message: '密码不能为空'},
                            stringLength: {min: 1,max: 30,message: '密码不能超过30个字符'}
                        }
                    },
                    uploadCycle: {
                        validators: {
                            notEmpty: {
                                message: '上传周期不能为空'
                            },
                            regexp: {
                                regexp: /^[0-9]+$/,
                                message: '必须为数字'
                            }
                        }
                    }
                }
            })
            .on('success.form.bv', function (e) {
                // 阻止默认提交事件
                e.preventDefault();
                // 获取form表单
                var $form = $(e.target);
                // Get the BootstrapValidator instance
                var bv = $form.data('bootstrapValidator');
                console.log($('#defaultForm').serialize());
                $.post($form.attr('action'), $form.serialize(), function(result) {
                    console.log(result);
                    var data = eval('('+result+')');
                    if (data.type == "alert") {
                        alert(data.message);
                    }
                    $('#defaultForm').prev().find("button").click();
                    $("#dataTable").bootstrapTable("selectPage",1);
                }, 'text');
            });
    }


</script>